<?php

// +----------------------------------------------------------------------
// | TAODUDU.COM  [ Simple Efficient Excellent ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://www.taodudu.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: ubten <462193409@qq.com> http://www.ubten.com/
// +----------------------------------------------------------------------

namespace Admin\Controller;
use Admin\Controller\AdminController;

class ConfigController extends AdminController {

    function _initialize() {
        parent::_initialize();
        $this->assign('sys', 'setting'); // 数据集
    }
    
    //网站核心配置文件
    public function sysconfig() {
        $cModel = M('config');
        $list = $cModel->where('groupid = 0')->select();
        foreach ($list as $key => $value) {
            $config[$value['name']] = $value['data'];
        }
        $this->assign('action', 'sysconfig');
        $this->assign('config', $config);
        $this->display();
    }

    //qq第三方登录配置
    public function qq() {
        $cModel = M('config');
        $list = $cModel->where('groupid = 1')->select();
        foreach ($list as $key => $value) {
            $config[$value['name']] = $value['data'];
        }
        $this->assign('action', 'qq');
        $this->assign('config', $config);
        $this->display();
    }

    //新浪第三方登录配置
    public function sina() {
        $cModel = M('config');
        $list = $cModel->where('groupid = 1')->select();
        foreach ($list as $key => $value) {
            $config[$value['name']] = $value['data'];
        }
        $this->assign('action', 'qq');
        $this->assign('config', $config);
        $this->display();
    }

    //微信第三方登录配置
    public function weixin(){
        $cModel = M('config');
        $list = $cModel->where('groupid = 1')->select();
        foreach ($list as $key => $value) {
            $config[$value['name']] = $value['data'];
        }
        $this->assign('action', 'qq');
        $this->assign('config', $config);
        $this->display();
    }

    
    //邮件配置
    public function email() {
        $cModel = M('config');
        $list = $cModel->where('groupid = 3')->select();
        foreach ($list as $key => $value) {
            $config[$value['name']] = $value['data'];
        }
        $this->assign('action', 'email');
        $this->assign('config', $config);
        $this->display();
    }

    
    //手机验证码配置
    public function mobile() {
        $cModel = M('config');
        $list = $cModel->where('groupid = 3')->select();
        foreach ($list as $key => $value) {
            $config[$value['name']] = $value['data'];
        }
        $this->assign('action', 'mobile');
        $this->assign('config', $config);
        $this->display();
    }

    
    //支付宝支付配置
    public function alipay() {
        $cModel = M('config');
        $list = $cModel->where('groupid = 2')->select();
        foreach ($list as $key => $value) {
            $config[$value['name']] = $value['data'];
        }
        $this->assign('config', $config);
        $this->assign('action', 'alipay');
        $this->display();
    }

    
    //微信支付配置
    public function wxpay() {
        $cModel = M('config');
        $list = $cModel->where('groupid = 2')->select();
        foreach ($list as $key => $value) {
            $config[$value['name']] = $value['data'];
        }
        $this->assign('config', $config);
        $this->assign('action', 'alipay');
        $this->display();
    }

    
    //银联支付配置
    public function unionpay() {
        $cModel = M('config');
        $list = $cModel->where('groupid = 2')->select();
        foreach ($list as $key => $value) {
            $config[$value['name']] = $value['data'];
        }
        $this->assign('config', $config);
        $this->assign('action', 'alipay');
        $this->display();
    }

    
    public function saveConfig() {
        if (IS_POST) {
            $cModel = M('config');
            $list = I();
            foreach ($list as $k => $v) {
                $currentData = array();
                $currentData['data'] = $v;
                $state = $cModel->where('name = "' . $k . '"')->save($currentData);
                if ($state === false) {
                    $this->error('修改失败！');
                }
            }
            $this->success("修改网站配置信息成功！");
        }
    }
    

}
